package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.bean.BannerBean;
import com.atwork.wuhua.bean.HomePageBean;
import com.atwork.wuhua.bean.TypesBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.IHomePageFragment;
import com.atwork.wuhua.ui.activity.MapActivity;
import com.atwork.wuhua.utils.LogUtils;
import com.atwork.wuhua.utils.SPUtils;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.model.LatLng;

public class HomePagePresenter extends BasePresenter<IHomePageFragment> {
    private double lat = 0;
    private double log = 0;

    public void getBanner() {
        BaseReq req = new BaseReq();
        req.setKey("page", "1");
        DataModel.request(Token.API_BANNER)
                .params(req)
                .execute(new Callback<BannerBean>() {

                    public void onSuccess(String msg, BannerBean data) {
                        getView().setBannerData(data);
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 获取场地分类
     */
    public void getTypes() {
        BaseReq req = new BaseReq();
        req.setKey("page", "1");
        DataModel.request(Token.API_TYPES)
                .params(req)
                .execute(new Callback<TypesBean>() {

                    public void onSuccess(String msg, TypesBean data) {
                        getView().setTypesData(data);
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 获取场馆列表
     */
    public void getLists(String type, int page, String keywords, String area, String orders, String sort) {
        if (lat == 0 || log == 0) {
            lat = Double.parseDouble(SPUtils.getString(getView().getContext(), SPUtils.LATITUDE));
            log = Double.parseDouble(SPUtils.getString(getView().getContext(), SPUtils.LONGITUDE));
        }

        BaseReq req = new BaseReq();
        if (keywords.length() > 0) {
            req.setKey("keywords", keywords);
        }
        if (area.length() > 0) {
            req.setKey("area", area);
        }

        if (orders.length() > 0) {
            req.setKey("orders", orders);
            req.setKey("sort", sort);
        }

        req.setKey("type", type);
        req.setKey("page", page + "");
        req.setKey("page_size", "10");
        req.setKey("position", log + "," + lat);
        LogUtils.e("场馆列表==>" + req.getString());
        DataModel.request(Token.API_LISTS)
                .params(req)
                .execute(new Callback<HomePageBean>() {

                    public void onSuccess(String msg, HomePageBean data) {
                        hideLoading();
                        getView().setLists(data);
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                        getView().noData();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }



}
